<%--
  Created by IntelliJ IDEA.
  User: 31921
  Date: 2024/12/14
  Time: 22:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%--<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>--%>
<html>
  <head>
    <title>学生管理系统 - 登录与注册</title>

  </head>
  <body>
    <div class="container">
      <h2>登录</h2>
      <!-- 登录表单 -->
      <form action="login" method="post">
        <input class="input-field" type="text" name="username" placeholder="用户名" required />
        <input class="input-field" type="password" name="password" placeholder="密码" required />
        <button type="submit" class="btn">登录</button>
      </form>

      <!-- 错误信息显示 -->
      <%--<c:if test="${not empty errorMessage}">
        <div class="error">${errorMessage}</div>
      </c:if>--%>
      <%
        String errorMessage = (String) request.getAttribute("errorMessage");
        if (errorMessage != null && !errorMessage.isEmpty()) {
      %>
      <div class="error"><%= errorMessage %></div>
      <%
        }
      %>

      <div class="link">
        还没有账号? <a href="javascript:void(0);" onclick="toggleForm('registerForm')">点击这里注册</a>
      </div>
    </div>

    <!-- 注册表单 -->
    <div class="container" id="registerForm" style="display:none;">
      <h2>注册</h2>
      <form action="register" method="post">
        <input class="input-field" type="text" name="username" placeholder="用户名" required />
        <input class="input-field" type="password" name="password" placeholder="密码" required />
        <input class="input-field" type="password" name="confirmPassword" placeholder="确认密码" required />
        <input class="input-field" type="email" name="email" placeholder="邮箱" required />
        <button type="submit" class="btn">注册</button>
      </form>

      <!-- 错误信息显示 -->
      <%--<c:if test="${not empty registerErrorMessage}">
        <div class="error">${registerErrorMessage}</div>
      </c:if>--%>
      <%
        String registerErrorMessage = (String) request.getAttribute("registerErrorMessage");
        if (registerErrorMessage != null && !registerErrorMessage.isEmpty()) {
      %>
      <div class="error"><%= registerErrorMessage %></div>
      <%
        }
      %>

      <div class="link">
        已有账号? <a href="javascript:void(0);" onclick="toggleForm('loginForm')">点击这里登录</a>
      </div>
    </div>

    <script>
      // 切换表单显示
      function toggleForm(formId) {
        if (formId === 'registerForm') {
          document.getElementById('registerForm').style.display = 'block';
          document.getElementById('loginForm').style.display = 'none';
        } else {
          document.getElementById('registerForm').style.display = 'none';
          document.getElementById('loginForm').style.display = 'block';
        }
      }
    </script>
  </body>
</html>

